package com.linkhub.oms.admin.modules.stock.domain.vo;

import com.linkhub.oms.common.util.QtBeanUtil;
import com.linkhub.oms.entity.resulttype.stock.ProductStockResultEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description: StockVO
 * @Author: echo
 * @Date: 2024/4/25 18:19
 * @Version: 1.0
 */
@Data
@ApiModel(value = "StockVO", description = "库存列表对象")
public class StockVO implements Serializable {

    @ApiModelProperty(value = "本地商品skuId")
    private String skuId;

    @ApiModelProperty(value = "sku")
    private String sku;

    @ApiModelProperty(value = "产品名称")
    private String productEnTitle;

    @ApiModelProperty(value = "imgUrl")
    private String imgUrl;

    @ApiModelProperty(value = "spu")
    private String spu;

    @ApiModelProperty(value = "仓库名称")
    private String stashName;

    @ApiModelProperty(value = "商家名称")
    private String merchantUserName;

    @ApiModelProperty(value = "可用库存")
    private Integer availableStock;

    @ApiModelProperty(value = "实物库存")
    private Integer physicalStock;

    @ApiModelProperty(value = "预占库存")
    private Integer preemptionStock;

    @ApiModelProperty(value = "冻结库存")
    private Integer frozenStock;

    @ApiModelProperty(value = "在途库存")
    private Integer passageStock;

    @ApiModelProperty(value = "次品数量")
    private Integer badAmount;

    public static StockVO convert(ProductStockResultEntity entity) {
        StockVO vo = new StockVO();
        QtBeanUtil.copyProperties(entity, vo);
        vo.setBadAmount(entity.getBadStock());
        vo.setPhysicalStock(entity.getGoodStock());
        vo.setAvailableStock(entity.getGoodStock() - entity.getPreemptionStock() - entity.getFrozenStock());

        return vo;
    }
}
